package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.servies.ShopService;
import com.fasterxml.jackson.annotation.JsonAlias;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class ShopController {

    @Autowired
    ShopService shopService;

    @RequestMapping("/findZong")
    public Object findZong(){
        List<Map> zong = shopService.findZong();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",zong.get(0).get("sum"));
        return jsonObject;
    }


    @RequestMapping("/findPer")
    public Object findPer(String nowDate){
        List<Map> per = shopService.findPer(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONArray data2Array = new JSONArray();
        for (Map map : per) {
            JSONObject data2Object = new JSONObject();
            data2Object.put("name",map.get("name"));
            data2Object.put("value",map.get("percent"));
            data2Array.add(data2Object);
        }
        JSONArray serArray = new JSONArray();
        JSONObject serObject = new JSONObject();
        serObject.put("name","series1");
        serObject.put("data",data2Array);
        serArray.add(serObject);

        JSONObject dataObject = new JSONObject();
        dataObject.put("series",serArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }

    @RequestMapping("/findPrivince")
    public Object findPrivince(){
        List<Map> list = shopService.findPrivince();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONArray mapArray = new JSONArray();
        for (Map map : list) {
            JSONObject mapObject = new JSONObject();
            mapObject.put("name",map.get("name"));
            mapObject.put("value",map.get("sum"));
            mapArray.add(mapObject);
        }
        JSONObject dataObject = new JSONObject();
        dataObject.put("mapData",mapArray);

        jsonObject.put("data",dataObject);
        return jsonObject;
    }

    @RequestMapping("showAll")
    public Object showAll(String status){
        List<Map> maps = shopService.showAll(status);
        for (Map map : maps) {
            System.out.println(map);
        }
        return 111;
    }


    @RequestMapping("findCount")
    public Object findCount(){
        List<Map> count = shopService.findCount();
        for (Map map : count) {
            System.out.println(map);
        }
        return 222;
    }


    @RequestMapping("findTotal")
    public Object findTotal(String name){
        List<Map> total = shopService.findTotal(name);
        for (Map map : total) {
            System.out.println(map);
        }
        return 333;
    }
}
